<template>
  <div>
    <div class="screen"> 
       <img v-if="isFullscreen" src="@/assets/icons/svg/exit-fullscreen.svg" @click="isclick">
       <img v-else src="@/assets/icons/svg/fullscreen.svg" @click="isclick">
      <!-- <svg-icon :name="isFullscreen?'exit-fullscreen':'fullscreen'" @click="isclick" /> -->
    </div> 
  </div>
</template>

<script>
import screenfull from "screenfull";

export default {
  name: "Screenfull",
  components: {
   
  },
  data() {
    return {
      isFullscreen: false,
    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    isclick() {
        // 判断是否支持
        if (!screenfull.enabled) {
          this.$message({
            message: "不支持全屏",  
            type: "warning"
          });
          return false;
        }
        screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off('change', this.change)
      }
    },
  }
};
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
.screen {
    width:20px;
    height:20px;
    margin-right: 15px;
    cursor: pointer;
    vertical-align: 10px;
    color: #5a5e66;
}
.screen img {
    width: 100%;
    height: 100%;
}
.screen:hover {
    cursor: pointer;
    background: rgba(0, 0, 0, 0.025);
    transition: background 0.3s;
}
</style>